//
//  Macro.h
//  HeaderMacro
//
//  Created by Burn on 2019/5/30.
//  Copyright © 2019 menksoft. All rights reserved.
//

#ifndef Macro_h
#define Macro_h
#import <UIKit/UIKit.h>


#define kFontName  @"HvrStudioChaganTig-M"

//$(SRCROOT)

//  播放相关的通知
//  播放状态变化
#define PLAYSTATUCHANGEKEY @"PLAYSTATUCHANGEKEY"
#define PLAYSTATUCHANGEKEY_MP4 @"PLAYSTATUCHANGEKEY_MP4"
//  全屏点击
#define FULLSCREENCLICK @"FULLSCREENCLICK"
//  URL不支持断点下载-1002
#define URLNAGETIVE1002 @"URL-1002"
//  右上方按钮点击
#define RiGHTTOPCLICK @"RiGHTTOPCLICK"
//  播放器返回按钮点击
#define PLAYBACK @"PLAYBACK"
//  二级页点击全屏通知
#define CLICKFULL @"CLICKFULL"


// 屏幕宽高
#define SCREEN_HEIGHT   [UIScreen mainScreen].bounds.size.height
#define SCREEN_WIDTH   [UIScreen mainScreen].bounds.size.width

#define CURRENT_SIZEWIDTH(_size) _size*SCREEN_WIDTH / 375.0
#define CURRENT_SIZEHEIGHT(_size) _size*SCREEN_HEIGHT / 667.0

//PlaceHolderImg
#define PlaceHolderImg  [UIImage imageNamed:@"testImg"]


/**
 * Macro For Color
 */
#pragma mark - Color
#define MK_BLACK(alpha) [[UIColor blackColor] colorWithAlphaComponent:alpha]
#define MK_WHITE(alpha) [[UIColor whiteColor] colorWithAlphaComponent:alpha]
#define MK_CLEAR [UIColor clearColor]
#define MK_COLOR(colorName,alpha) [[UIColor colorName] colorWithAlphaComponent:alpha]
#define MK_COLOR_Alpha(color,alpha) [color colorWithAlphaComponent:alpha]
#define MK_RGBCOLOR(r,g,b) [UIColor colorWithRed:(r)/255.0f green:(g)/255.0f blue:(b)/255.0f alpha:1]
#define MK_HEXCOLOR(hexCode) [UIColor colorWithRed:((hexCode>>16)&0xFF)/255.0 green:((hexCode>>8)&0xFF)/255.0 blue:((hexCode)&0xFF)/255.0 alpha:1.0]
#define MK_HEXCOLOR_Alpha(hexCode,alpha) [[UIColor colorWithRed:((hexCode>>16)&0xFF)/255.0 green:((hexCode>>8)&0xFF)/255.0 blue:((hexCode)&0xFF)/255.0 alpha:1.0] colorWithAlphaComponent:alpha]

#define RGBACOLOR(r, g, b, a) [UIColor colorWithRed:(r)/255.0 green:(g)/255.0 blue:(b)/255.0 alpha:(a)]
#define MK_RANDOMCOLOR [UIColor colorWithRed:arc4random_uniform(255) / 255.0 green:arc4random_uniform(255) / 255.0 blue:arc4random_uniform(255) / 255.0 alpha:1]


/**
 * Macro For Font
 */
#pragma mark - Font
#define PJ_FONT [UIFont fontWithName:@"PingFangSC-Regular"]
#define MK_FONT(size) [UIFont systemFontOfSize:size]
#define MK_BOLDFONT(size) [UIFont boldSystemFontOfSize:size]
#define MK_FONT_N(fontName,fontSize) [UIFont fontWithName:fontName size:fontSize]


//程序全局委托
#define appDelegate   ((AppDelegate *)[[UIApplication sharedApplication] delegate])
//UserDefaults
#define UserDefaults [NSUserDefaults standardUserDefaults]
//语言设置
#define KSetLanguage(x)                     [[NSUserDefaults standardUserDefaults]setObject:(x) forKey:@"use_language"]
#define KGetLanguage                        [[NSUserDefaults standardUserDefaults]stringForKey:@"use_language"]
#define KIsChinese                          [KGetLanguage isEqualToString:@"cn"]
#define KIsMn                               [KGetLanguage isEqualToString:@"mn"]

#define Img(img)                            [UIImage imageNamed:img]
#define Url(url)                            [NSURL URLWithString:url]



//蒙科立字体
#define MenksoftQagan_mirror(x)          [UIFont fontWithName:@"HvrStudioChaganTig-M" size:x] //蒙科立镜像字体
#define HvrStudioChaganTig_M(x)          [UIFont fontWithName:@"HvrStudioChaganTig-M" size:x] //标准编码使用
#define MenkTransform                    CGAffineTransformConcat(CGAffineTransformMakeRotation(M_PI_2), CGAffineTransformMake(-1, 0, 0, 1, 0, 0))
#define MenkRotation                     CGAffineTransformMakeRotation(M_PI_2)


//iPhone_X
#define IS_IPHONE (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone)
#define IS_IOS_11  ([[[UIDevice currentDevice] systemVersion] floatValue] >= 11.f)
#define IS_IPHONE_X (IS_IOS_11 && IS_IPHONE && (MIN([UIScreen mainScreen].bounds.size.width, [UIScreen mainScreen].bounds.size.height) >= 375 && MAX([UIScreen mainScreen].bounds.size.width, [UIScreen mainScreen].bounds.size.height) >= 812))

// iPhone5 iPhone5s iPhoneSE
#define IS_iPhone_5 ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(640, 1136), [[UIScreen mainScreen] currentMode].size) : NO)

// iPhone6 7 8
#define IS_iPhone_6 ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? (CGSizeEqualToSize(CGSizeMake(750, 1334), [[UIScreen mainScreen] currentMode].size) || CGSizeEqualToSize(CGSizeMake(640, 1136), [[UIScreen mainScreen] currentMode].size)) : NO)

// iPhone6plus  iPhone7plus iPhone8plus
#define IS_iPhone6_Plus ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? (CGSizeEqualToSize(CGSizeMake(1125, 2001), [[UIScreen mainScreen] currentMode].size) || CGSizeEqualToSize(CGSizeMake(1242, 2208), [[UIScreen mainScreen] currentMode].size)) : NO)

// iPhoneX
#define IS_iPhoneX ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(1125, 2436), [[UIScreen mainScreen] currentMode].size) : NO)

// iPhoneXR
#define IS_iPhoneXR ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(828, 1792), [[UIScreen mainScreen] currentMode].size) : NO)

// iPhoneXS Max
#define IS_iPhoneXSMax ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(1242, 2688), [[UIScreen mainScreen] currentMode].size) : NO)

#define SafeAreaTopHeight (SCREEN_HEIGHT >= 812.0 ? 88 : 64)
#define SafeAreaBottomHeight (SCREEN_HEIGHT >= 812.0 ? 34 : 0)
#define SafeAreaStatuBarHeight (SCREEN_HEIGHT >= 812.0 ? 44 : 20)
#define SafeAreaValueHeight (SCREEN_HEIGHT >= 812.0 ? 24 : 0)
#define SafeAreaLiuHiaHeight (SCREEN_HEIGHT >= 812.0 ? 30 : 0)



#define kIs_iphone (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone)
#define kIs_iPhoneX SCREEN_WIDTH >=375.0f && SCREEN_HEIGHT >=812.0f&& kIs_iphone

/*TabBar高度*/
#define kTabBarHeight (CGFloat)(kIs_iPhoneX?(49.0 + 34.0):(49.0))

//DEBUG操作
#ifdef DEBUG
#define DLOG(...)   NSLog(__VA_ARGS__)
#define DLOGPOINT(p)    NSLog(@"%f,%f", p.x, p.y);
#define DLOGSIZE(size)    NSLog(@"%f,%f", size.width, size.height);
#define DLOGRECT(p)    NSLog(@"%f,%f %f,%f", p.origin.x, p.origin.y, p.size.width, p.size.height);
#else
#define DLOG(...)
#define DLOGPOINT(p)
#define DLOGSIZE(p)
#define DLOGRECT(p)
#endif





//#ifdef DEBUG
//#define DLog(...) NSLog(@"%s(%p) %@", __PRETTY_FUNCTION__, self, [NSString stringWithFormat:__VA_ARGS__])
//#else
//#define DLog(...)
//#endif




#define IOS8            ([[[UIDevice currentDevice] systemVersion] doubleValue] >= 8.0)
//是否为ios9
#ifndef IOS9
#define IOS9            ([[[UIDevice currentDevice] systemVersion] floatValue] >= 9.0?YES:NO)
#endif


#pragma mark - Tools methods
/**
 *  判断一个对象是否为空
 *
 *  @param thing 对象
 *
 *  @return 返回结果
 */
static inline BOOL ICIsObjectEmpty(id thing){
    return thing == nil ||
    ([thing isEqual:[NSNull null]]) ||
    ([thing respondsToSelector:@selector(length)] && [(NSData *)thing length] == 0) ||
    ([thing respondsToSelector:@selector(count)]  && [(NSArray *)thing count] == 0);
}

/**
 *  判断一个字符串是否为空
 *
 *  @param string 字符串
 *
 *  @return 返回结果
 */
static inline BOOL ICIsStringEmpty(NSString *string){
    
    if (![string isKindOfClass:[NSString class]]) {
        
        string = [NSString stringWithFormat:@"%@",string];
    }
    
    if (string == nil) {
        return YES;
    }
    
    if (string.length == 0) {
        return YES;
    }
    
    if ([string isEqualToString:@"<null>"]) {
        return YES;
    }
    
    if ([string isEqualToString:@"(null)"]) {
        return YES;
    }
    
    return NO;
}

/**
 *  弱引用对象
 *
 *  @param self 当前对象
 *
 *  @return 弱应用对象
 */
#define WEAKSELF typeof(self) __weak weakSelf = self;

/**
 *  强引用对象
 *
 *  @param self 当前对象
 *
 *  @return 强引用对象
 */
#define STRONGSELF typeof(self) __strong strongSelf = self;

#endif /* Macro_h */




//条件编译
#if __has_feature(objc_arc)
//ARC

//#define IMSingletonH(name) + (instancetype)shared##name;
//+ (instancetype)shared##name{\

//.h头文件中的单例宏  sharedRemotePlayerFileManager
#define IMSingletonH + (instancetype)shared;

//.m文件中的单例宏
#define IMSingletonM \
static id _instance;\
+ (instancetype)allocWithZone:(struct _NSZone *)zone{\
static dispatch_once_t onceToken;\
dispatch_once(&onceToken, ^{\
_instance = [super allocWithZone:zone];\
});\
return _instance;\
}\
+ (instancetype)shared{\
static dispatch_once_t onceToken;\
dispatch_once(&onceToken, ^{\
_instance = [[self alloc] init];\
});\
return _instance;\
}\
- (id)copyWithZone:(NSZone *)zone{\
return _instance;\
}



#else
//MRC


//.h头文件中的单例宏
#define IMSingletonH(name) + (instancetype)shared##name;

//.m文件中的单例宏
#define IMSingletonM(name) \
static id _instance;\
+ (instancetype)allocWithZone:(struct _NSZone *)zone{\
static dispatch_once_t onceToken;\
dispatch_once(&onceToken, ^{\
_instance = [super allocWithZone:zone];\
});\
return _instance;\
}\
+ (instancetype)shared##name{\
static dispatch_once_t onceToken;\
dispatch_once(&onceToken, ^{\
_instance = [[self alloc] init];\
});\
return _instance;\
}\
- (id)copyWithZone:(NSZone *)zone{\
return _instance;\
}\
- (oneway void)release{\
}\
- (instancetype)retain{\
return self;\
}\
- (NSUInteger)retainCount{\
return 1;\
}\
- (instancetype)autorelease{\
return self;\
}



#endif
